﻿scene.light = (function ($, undefined)
{
    var init = function ()
    {
    };
    
    var destroy = function ()
    {
    };

    var addLightsToScene = function (scene)
    {
        var positions = [new THREE.Vector3(50, 80, 100)/*, new THREE.Vector3(-50, 0, 100), new THREE.Vector3(0, 0, 0)*/];
        
        $.each(positions, function (i, position) {
            var light = _createPointLight(position);
            scene.add(light);
            var ambientLight = _ambientPointLight(position);
            scene.add(ambientLight);
        });
    };

    var _createPointLight = function (position)
    {
        var light = new THREE.PointLight(0xffffff);
        light.position = position;

        return light;
    };

    var _ambientPointLight = function (position) {
        var light = new THREE.AmbientLight(0xff0000);
        light.position = position;

        return light;
    };

    var _directionalLight = function (position) {
        var light = new THREE.DirectionalLight(0xffffff);
        light.position = position;

        return light;
    };

    var _createSpotLight = function (position)
    {
        var light = new THREE.SpotLight(0xffffff);
        light.position = position;

        light.shadowCameraVisible = true;
        light.shadowDarkness = 0.95;
        light.intensity = 0.9;
        light.castShadow = true;

        light.shadowMapWidth = 1024;
        light.shadowMapHeight = 1024;

        light.shadowCameraNear = 500;
        light.shadowCameraFar = 4000;
        light.shadowCameraFov = 30;

        return light;
    };

    var _createAreaLight = function (position)
    {
        var light = new THREE.AreaLight(0xffffff, 1);

        light.position = position;

        light.rotation.set(0.74719, 0.0001, 0.0001);
        light.width = 10;
        light.height = 10;

        return light;
    };

    // public API
    return {
        init: init,
        destroy: destroy,
        addLightsToScene: addLightsToScene
    };
})(jQuery);